﻿#region Header

// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Linq;
using Majesty_of_Omega.GUI.Pages.Game.Research;
#if NUNIT
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;
#elif MBUNIT
using MbUnit.Framework;
using TestClass = MbUnit.Framework.TestFixtureAttribute;
using TestMethod = MbUnit.Framework.TestAttribute;
using TestInitialize = MbUnit.Framework.SetUpAttribute;
using TestCleanup = MbUnit.Framework.TearDownAttribute;
using ClassInitialize = MbUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = MbUnit.Framework.TestFixtureTearDownAttribute;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif

using Majesty_of_Omega.GUI.Controller;
using Majesty_of_Omega.Config;
using System;

#endregion

namespace Test.Majesty_of_Omega.GUI.Controller
{
    /// <summary>
    /// Summary description for TestResearchPageController
    /// </summary>
    [TestClass]
    public class TestResearchPageController
    {
        /// <summary>
        /// Tests the <see cref="ResearchPageController" /> constructor.
        /// </summary>
        [TestMethod]
        public void TestResearchPageConstructor()
        {
            var controller = new ResearchPageController();
            var schools = controller.TechSchoolResearchList;
            Assert100Percent(schools);
        }

        /// <summary>
        /// Assert100s the percent.
        /// </summary>
        /// <param name="infoCollection">The info collection.</param>
        private static void Assert100Percent(ResearchPageController.TechInfoCollection infoCollection)
        {
            Assert.AreEqual(100, infoCollection.SumOfResearchPoints, "The sum of all research points must be 100");
        }


        /// <summary>
        /// Tests the change of a research item. The sum of all research items must stay at 100 percent
        /// </summary>
        [TestMethod]
        public void TestChangeOfResearchItem()
        {
            var controller = new ResearchPageController();
            var schools = controller.TechSchoolResearchList;
            Assert100Percent(schools);
            schools[0].Percentage = 99; // change to extremo of 99%
            Assert100Percent(schools);
            schools[0].Percentage = 0;
            Assert100Percent(schools);
        }

        /// <summary>
        /// Test access to the funding level info collection
        /// </summary>
        [TestMethod]
        public void TestFundinglevels()
        {
            var controller = new ResearchPageController();
            Assert.AreEqual(Enum.GetValues(typeof(FundingLevel)).Length, controller.FundingLevelInfoLevels.Count());
        }

        /// <summary>
        /// Tests the signals by changing A funding level.
        /// </summary>
        [TestMethod]
        public void TestSignalsByChangingAFundingLevel()
        {
            bool bSignalOfChange = false;
            var controller = new ResearchPageController();

            //var appliedResearchItem = new AppliedResearchItem("HydroFrm");
            //controller.ResearchManager.TechAvailableAppliedResearchs.Add(appliedResearchItem);
            //controller.ResearchManager.AddResearchToCurrentAppliedResearchProjects(appliedResearchItem);

            // the following statement sets a delegate, which sets the bSignalOfChange
            // variable on true, wenn the observable collection detects a change
            controller.CurrentAppliedTechnologiesList.CollectionChanged += delegate
                {
                    bSignalOfChange = true;
                };


            // select the third applied technology of the current research projects of the test game
            controller.SelectedAppliedResearch = controller.CurrentAppliedTechnologiesList[0];

            // change funding level.
            controller.SelectedAppliedResearchFunding = FundingLevel.Half;

            // now we must have a signal of change, because a notify of our changed entry must be raised
            Assert.IsTrue(bSignalOfChange);
        }
    }
}